package com.xlkj.ms.tools.core.response;

import com.xlkj.ms.tools.core.model.Meta;

import java.util.List;

/**
 * <pre>
 * {@code
 * {
 *     "code":"****",
 *     "msg":"****",
 *     "data":[{***},{***}],
 *     "meta":{"total":***}
 * }
 * }
 * </pre>
 * @author zhuqifeng
 * @date 2021/11/10 13:55
 * @package com.xlkj.ms.tools.core.response
 */
public abstract class AbstractListWithMetaResponseWrapper<E> extends AbstractResponse{

    private static final long serialVersionUID = -8899026577303006272L;

    private List<E> data;

    private Meta meta;

    public AbstractListWithMetaResponseWrapper() {
    }

    public AbstractListWithMetaResponseWrapper(String code, String msg, List<E> data, long total) {
        super(code, msg);
        this.data = data;
        this.meta = new Meta(total);
    }

    public AbstractListWithMetaResponseWrapper(String code, String msg) {
        super(code, msg);
    }

    public AbstractListWithMetaResponseWrapper(List<E> data, Meta meta) {
        this.data = data;
        this.meta = meta;
    }

    public AbstractListWithMetaResponseWrapper(List<E> data, long total) {
        this.data = data;
        this.meta = new Meta(total);
    }

    public AbstractListWithMetaResponseWrapper(List<E> data) {
        this.data = data;
        this.meta = new Meta(null!=data?data.size():0);
    }

    public List<E> getData() {
        return data;
    }

    public void setData(List<E> data) {
        this.data = data;
    }

    public Meta getMeta() {
        return meta;
    }

    public void setMeta(Meta meta) {
        this.meta = meta;
    }

    public void injectTotal(long total) {
        this.meta = new Meta(total);
    }
}